﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using LuKou.Web.Controllers.Base;
using LuKou.Web.Core;
using LuKou.Web.UserAuth;

namespace LuKou.Web.Controllers.Manage
{
    public class LoginController : ManageBaseController
    {
        [HttpGet]
        public ActionResult Index()
        {
            return View("login");
        }

        [HttpPost]
        public ActionResult Index(string UserName, string PassWord, string ReferrerUrl)
        {
            if (!UserName.IsNullOrEmpty() && !PassWord.IsNullOrEmpty() )
            {
                this.Membership.Write(new UserModel()
                {
                    UID = 1,
                    UserName = UserName,
                });

                if (ReferrerUrl.IsNullOrEmpty())
                    return RedirectToAction("Index");
                else
                    return Redirect(ReferrerUrl);
            }

            TempData["Error"]= "用户名或密码错误";
            return View("login");
        }

        public ActionResult Logout()
        {
            this.Membership.Logout();
            return RedirectToAction("Index", "Home");
        }
    }
}
